<?php 
//    print_r($this->aUser); 
//    print_r($this->aProject);
?>

<table width="100%" cellspacing="0" cellpadding="8" class="newsfeed" id="myTable" border="0"  valign="top">
<thead>
	<tr>
		<th>User</th>
		<th>Project</th>
		<th>Start Date</th>
        <th>End Date</th>
        <th>Endless</th>                
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
<form method="post" action="/admin/usertoproject/add">
<tr>
    <td>
            <select  name="filter_user">
                <option value="" >Select user</option>
   			    <?php 
			         foreach ($this->aUser as $oUser)
			         {
			    ?>               
                <option value="<?php echo $oUser->email?>" ><?php echo $oUser->email; ?></option>
                <?php } ?>
            </select>
    </td>
    
    <td>
            <select  name="filter_project" id="filter_project">
                <option value="" start_date="" end_date="">Select project</option>
                <?php 
                     foreach ($this->aProject as $oProject)
                     {
                ?>               
                <option value="<?php echo $oProject->name?>" start_date="<?php echo $oProject->start_date; ?>" end_date="<?php echo $oProject->end_date; ?>"  ><?php echo $oProject->name; ?></option>
                <?php } ?>
            </select>
    </td>
    
    <td>
        <input type="text" name="start_date" id="start_date" />
    </td>
     
    <td>
        <input type="text" name="end_date" id="end_date" />
    </td>
    
    <td>
        <input type="checkbox" name="endless" id="endless" />
    </td>

    <td>
        <input type="submit" value="Add" />
    </td>
</form>    
</tr>

</thead>    
<tbody>

	<?php
	
	foreach ($this->paginator as $oUser)
	{
		?>
	<tr class="{id: '<?php echo $oUser['id_user'] . '_' . $oUser['id_project']; ?>'}" valign="top">
		
        <td class="{field: 'id_user'}"><?php echo models_UserMapper::findById($this->escape($oUser['id_user']))->email; ?></td>
		<td class="{field: 'id_project'}"><?php 
		  $project = models_ProjectMapper::findById($this->escape($oUser['id_project']));
		if (isset($project->name)) 
		  echo $project->name; ?>
          </td>
        <td class="{field: 'start_date'}"><?php echo $this->escape($oUser['start_date']); ?></td>
        <td class="{field: 'end_date'}"><?php echo $this->escape($oUser['end_date']); ?></td>
        <td class="{field: 'endless'}"><?php echo $this->escape($oUser['endless']); ?></td>


		<td class="del_element"><a
			href="/admin/usertoproject/edit/id/<?php echo $oUser['id_user'] . '_' . $oUser['id_project']; ?>" class="sexybutton sexysimple sexygreen"><span class="edit">Edit</span></a>
        </td>
        <td class="del_element"><a
            href="/admin/usertoproject/delete/id/<?php echo $oUser['id_user'] . '_' . $oUser['id_project']; ?>" class="sexybutton sexysimple sexygreen"><span class="delete">Delete</span></a>
        </td>
	</tr>
	<?php
	}
	?>
	
</tbody>	
</table>

	<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
